var http = require('http')
var fs = require('fs')

// 1. 创建Server
var server = http.createServer()

var wwwDir = 'D:/app/www'

server.on('request', function (request, response) {
    var url = request.url // 注意啊  这个变量url就是浏览器地址栏输入的url  比如 /a.txt
    var filePath = '/index .html'
    if (url !== '/') {
        filePath = url
    }
    console.log(filePath, wwwDir + filePath)

    fs.readFile(wwwDir + filePath, function (err, data) {
        if (err) {
            return response.end('404 Not Found .')
        }
        response.end(data)
    })
})

// 3.绑定端口号，启动服务
server.listen(3000, function () {
    console.log('server is running ... ')
})